/* import type { Metadata } from "next";
* import "./globals.css";
* import ThemeProvider from "@/context/theme/Theme.provider";

* export const metadata: Metadata = {
*   title: "Create Next App",
*   description: "Generated by create next app",
* };

* export default function RootLayout({
*   children,
* }: Readonly<{
*   children: React.ReactNode;
* }>) {
*   return (
*     <html lang="en">
*       <body className={`antialiased dark:bg-black`}>
*         <ThemeProvider> {children}</ThemeProvider>
*       </body>
*     </html>
*   );
* }

 * refer above code for the layout.tsx file
 * This file is used to set up the layout for the application, including metadata and global styles
 * It also wraps the application in a ThemeProvider for consistent theming across the app.
 * The layout is designed to be flexible and can be extended with additional providers or configurations as needed
 */

// app/[locale]/layout.tsx
import type { Metadata } from "next";
import "../../styles/globals.css";
import { NextIntlClientProvider } from "next-intl";
import { getMessages } from "next-intl/server";
import { routing, locale as LocaleType } from "@/i18n/routing";
import { notFound } from "next/navigation";
import ThemeProvider from "@/context/theme/Theme.provider";

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

// Define a type for your layout component's props
// This type is crucial and must match what Next.js expects for layout params
type RootLayoutProps = {
  children: React.ReactNode;
  params: {
    locale: string; // The locale dynamic segment will be a string
  };
};

export default async function RootLayout({
  children,
  params,
}: RootLayoutProps) {
  const { locale } = await params; // Destructure locale directly

  // Ensure the type assertion is correct and refers to your i18n locale type
  if (!routing.locales.includes(locale as LocaleType)) {
    notFound();
  }
  const messages = await getMessages();

  return (
    <html lang={locale}>
      <body className="antialiased">
        <NextIntlClientProvider locale={locale} messages={messages}>
          <ThemeProvider>{children}</ThemeProvider>
        </NextIntlClientProvider>
      </body>
    </html>
  );
}
